<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>图书详情</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    <link th:href="@{/css/style.css}" rel="stylesheet">
    <style>
        .book-cover-large {
            max-width: 300px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }
        .book-info {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            padding: 30px;
            margin-bottom: 30px;
        }
        .rating {
            color: #ffc107;
            font-size: 24px;
        }
        .rating-input {
            display: none;
        }
        .rating-star {
            cursor: pointer;
            color: #ddd;
            font-size: 24px;
        }
        .rating-star:hover,
        .rating-star:hover ~ .rating-star {
            color: #ffc107;
        }
        .rating-input:checked ~ .rating-star {
            color: #ffc107;
        }
        .comment-card {
            background: white;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .comment-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        .comment-time {
            color: #666;
            font-size: 0.9em;
        }
    </style>
</head>
<body>
    <div id="particles-js"></div>
    
    <div class="container mt-5">
        <div class="book-info">
            <div class="row">
                <div class="col-md-4 text-center">
                    <img th:if="${book.coverUrl}" th:src="${book.coverUrl}" class="book-cover-large" alt="封面">
                    <img th:unless="${book.coverUrl}" src="/img/default-cover.jpg" class="book-cover-large" alt="默认封面">
                </div>
                <div class="col-md-8">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a th:href="@{/books}">图书列表</a></li>
                            <li class="breadcrumb-item active" aria-current="page">图书详情</li>
                        </ol>
                    </nav>
                    <h1 class="mb-4" th:text="${book.title}">书名</h1>
                    <div class="mb-3">
                        <strong>作者：</strong>
                        <span th:text="${book.author}"></span>
                    </div>
                    <div class="mb-3">
                        <strong>价格：</strong>
                        <span th:text="${'¥' + #numbers.formatDecimal(book.price, 1, 2)}"></span>
                    </div>
                    <div class="mb-3">
                        <strong>库存：</strong>
                        <span th:text="${book.stock}"></span>
                    </div>
                    <div class="mb-4">
                        <strong>描述：</strong>
                        <p th:text="${book.description}" class="mt-2"></p>
                    </div>
                </div>
            </div>
        </div>

        <div class="book-info">
            <h3 class="mb-4">读者评论</h3>
            
            <!-- 添加评论表单 -->
            <form th:action="@{/books/detail/{id}/comment(id=${book.id})}" method="post" th:object="${newComment}" class="mb-5">
                <div class="mb-3">
                    <label for="commenterName" class="form-label">您的名字</label>
                    <input type="text" class="form-control" id="commenterName" th:field="*{commenterName}" required>
                </div>
                <div class="mb-3">
                    <label class="form-label">评分</label>
                    <div class="rating-group">
                        <input type="radio" name="rating" value="5" id="star5" class="rating-input" th:field="*{rating}">
                        <label for="star5" class="rating-star"><i class="fas fa-star"></i></label>
                        <input type="radio" name="rating" value="4" id="star4" class="rating-input" th:field="*{rating}">
                        <label for="star4" class="rating-star"><i class="fas fa-star"></i></label>
                        <input type="radio" name="rating" value="3" id="star3" class="rating-input" th:field="*{rating}">
                        <label for="star3" class="rating-star"><i class="fas fa-star"></i></label>
                        <input type="radio" name="rating" value="2" id="star2" class="rating-input" th:field="*{rating}">
                        <label for="star2" class="rating-star"><i class="fas fa-star"></i></label>
                        <input type="radio" name="rating" value="1" id="star1" class="rating-input" th:field="*{rating}">
                        <label for="star1" class="rating-star"><i class="fas fa-star"></i></label>
                    </div>
                </div>
                <div class="mb-3">
                    <label for="content" class="form-label">评论内容</label>
                    <textarea class="form-control" id="content" rows="3" th:field="*{content}" required></textarea>
                </div>
                <button type="submit" class="btn btn-primary">提交评论</button>
            </form>

            <!-- 评论列表 -->
            <div th:if="${not #lists.isEmpty(comments)}">
                <div th:each="comment : ${comments}" class="comment-card">
                    <div class="comment-header">
                        <div>
                            <strong th:text="${comment.commenterName}">评论者</strong>
                            <span class="rating ms-2">
                                <i class="fas fa-star" th:each="i : ${#numbers.sequence(1, comment.rating)}"></i>
                            </span>
                        </div>
                        <span class="comment-time" th:text="${#temporals.format(comment.createTime, 'yyyy-MM-dd HH:mm')}">时间</span>
                    </div>
                    <p class="mb-0" th:text="${comment.content}">评论内容</p>
                </div>
            </div>
            <div th:if="${#lists.isEmpty(comments)}" class="text-center text-muted">
                暂无评论，来写第一条评论吧！
            </div>
        </div>
    </div>
    
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
    <script>
        particlesJS('particles-js', {
            particles: {
                number: { value: 80, density: { enable: true, value_area: 800 } },
                color: { value: '#ffffff' },
                shape: { type: 'circle' },
                opacity: { value: 0.5, random: false },
                size: { value: 3, random: true },
                line_linked: {
                    enable: true,
                    distance: 150,
                    color: '#ffffff',
                    opacity: 0.4,
                    width: 1
                },
                move: {
                    enable: true,
                    speed: 6,
                    direction: 'none',
                    random: false,
                    straight: false,
                    out_mode: 'out',
                    bounce: false
                }
            },
            interactivity: {
                detect_on: 'canvas',
                events: {
                    onhover: { enable: true, mode: 'repulse' },
                    onclick: { enable: true, mode: 'push' },
                    resize: true
                }
            },
            retina_detect: true
        });

        // 评分系统
        document.querySelectorAll('.rating-star').forEach(star => {
            star.addEventListener('click', function() {
                const rating = this.previousElementSibling.value;
                document.querySelectorAll('.rating-star').forEach(s => {
                    s.style.color = '#ddd';
                });
                let current = this;
                while (current) {
                    current.style.color = '#ffc107';
                    current = current.nextElementSibling;
                }
            });
        });
    </script>
</body>
</html> 